package com.eshop.modules.activity.service.mapper;

import org.apache.ibatis.annotations.Select;
import com.eshop.modules.activity.service.dto.PinkDto;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.eshop.modules.activity.domain.StorePink;
import com.eshop.common.mapper.CoreMapper;

@Repository
public interface StorePinkMapper extends CoreMapper<StorePink>
{
    @Select({ "SELECT p.id,p.uid,p.people,p.price,p.stop_time as stopTime,u.nickname,u.avatar FROM store_pink p INNER JOIN eshop_user u ON u.uid=p.uid WHERE stop_time > now() AND p.cid = #{cid} AND p.k_id = 0 AND p.is_refund = 0 ORDER BY p.create_time DESC" })
    List<PinkDto> getPinks(final Long cid);
    
    @Select({ "SELECT p.id,u.nickname,u.avatar FROM store_pink p RIGHT  JOIN eshop_user u ON u.uid=p.uid where p.status= 2 AND p.uid <> ${uid} AND p.is_refund = 0" })
    List<PinkDto> getPinkOkList(final Long uid);
    
    @Select({ "SELECT p.id,p.uid,p.people,p.price,p.stop_time as stopTime,u.nickname,u.avatar FROM store_pink p LEFT JOIN eshop_user u ON u.uid=p.uid where p.k_id= ${kid} AND p.is_refund = 0" })
    List<PinkDto> getPinkMember(final int kid);
    
    @Select({ "SELECT p.id,p.uid,p.people,p.price,p.stop_time as stopTime,u.nickname,u.avatar FROM store_pink p LEFT JOIN eshop_user u ON u.uid=p.uid where p.id= ${id} " })
    PinkDto getPinkUserOne(final int id);
    
    @Select({ "select IFNULL(sum(total_num),0) from store_pink where status=2 and is_refund=0" })
    int sumNum();
}
